package com.jy.adscm.operation.yx.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.operation.yx.bean.Hospital;
import com.jy.adscm.operation.yx.bean.QueryHospital;
import com.jy.adscm.operation.yx.mapper.mysql.HospitalMapper;
import com.jy.adscm.operation.yx.service.HospitalService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-07-24
 */
@Service
public class HospitalServiceImpl extends ServiceImpl<HospitalMapper, Hospital> implements HospitalService {

    @Override
    public Page<Hospital> selectHospital(Page<Hospital> page, QueryHospital queryHospital) {

        Wrapper<Hospital> wrapper =new EntityWrapper<>();
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryHospital.getHospitalName(),null)){
            wrapper.like("hospital_name",queryHospital.getHospitalName());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryHospital.getHospitalAlias(),null)){
            wrapper.like("hospital_alias",queryHospital.getHospitalAlias());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryHospital.getLocation(),null)){
            wrapper.like("location",queryHospital.getLocation());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryHospital.getProvince(),null)){
            wrapper.like("province",queryHospital.getProvince());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryHospital.getCity(),null)){
            wrapper.like("city",queryHospital.getCity());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryHospital.getTags(),null)){
            wrapper.like("tags",queryHospital.getTags());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryHospital.getDepartment(),null)){
            wrapper.like("department",queryHospital.getDepartment());
        }
        page= super.selectPage(page,wrapper);
        page.setTotal(super.selectCount(wrapper));

        return page;
    }
}
